@model ForumGroupSearchModel

@{
    //page title
    ViewBag.Title = T("Admin.ContentManagement.Forums.Manage").Text;
    //active menu item (system name)
    Html.SetActiveMenuItemSystemName("Manage forums");
}

<nop-antiforgery-token/>
<div class="content-header clearfix">
    <h1 class="pull-left">
        @T("Admin.ContentManagement.Forums.Manage")
    </h1>
    <div class="pull-right">
        <a asp-action="CreateForumGroup" class="btn btn-primary">@T("Admin.ContentManagement.Forums.ForumGroup.CreateForumGroup")</a>
        <a asp-action="CreateForum" class="btn btn-primary">@T("Admin.ContentManagement.Forums.Forum.CreateForum")</a>
        @await Component.InvokeAsync("AdminWidget", new { widgetZone = AdminWidgetZones.ForumListButtons })
    </div>
</div>

<div class="content">
    <div class="form-horizontal">
        <div class="panel-group">
            <div class="panel panel-default">
                <div class="panel-body">
                    <div id="forumgroup-grid"></div>

                    <script>
                        $(document).ready(function() {
                            $("#forumgroup-grid").kendoGrid({
                                dataSource: {
                                    type: "json",
                                    transport: {
                                        read: {
                                            url: "@Html.Raw(Url.Action("ForumGroupList", "Forum"))",
                                            type: "POST",
                                            dataType: "json",
                                            data: addAntiForgeryToken
                                        }
                                    },
                                    schema: {
                                        data: "Data",
                                        total: "Total",
                                        errors: "Errors"
                                    },
                                    error: function(e) {
                                        display_kendoui_grid_error(e);
                                        // Cancel the changes
                                        this.cancelChanges();
                                    },
                                    pageSize: @(Model.PageSize),
                                    serverPaging: true,
                                    serverFiltering: true,
                                    serverSorting: true
                                },
                                pageable: {
                                    refresh: true,
                                    pageSizes: [@(Model.AvailablePageSizes)],
                                    @await Html.PartialAsync("_GridPagerMessages")
                                },
                                //details grid
                                detailInit: detailInit,
                                scrollable: false,
                                columns: [
                                    {
                                        field: "Name",
                                        title: "@T("Admin.ContentManagement.Forums.ForumGroup.Fields.Name")",
                                        width: 300
                                    }, {
                                        field: "DisplayOrder",
                                        title: "@T("Admin.ContentManagement.Forums.ForumGroup.Fields.DisplayOrder")",
                                        width: 100
                                    }, {
                                        field: "CreatedOn",
                                        title: "@T("Admin.ContentManagement.Forums.ForumGroup.Fields.CreatedOn")",
                                        width: 200,
                                        type: "date",
                                        format: "{0:G}"
                                    }, {
                                        field: "Id",
                                        title: "@T("Admin.Common.Edit")",
                                        width: 80,
                                        headerAttributes: { style: "text-align:center" },
                                        attributes: { style: "text-align:center" },
                                        template: '<a class="btn btn-default" href="EditForumGroup/#=Id#"><i class="fa fa-pencil"></i>@T("Admin.Common.Edit")</a>'
                                    }
                                ]
                            });
                        });

                        //details grid
                        function detailInit(e) {
                            $("<div/>").appendTo(e.detailCell).kendoGrid({
                                dataSource: {
                                    type: "json",
                                    transport: {
                                        read: {
                                            url: "@Html.Raw(Url.Action("ForumList", "Forum"))",
                                            type: "POST",
                                            dataType: "json",
                                            data: function() {
                                                var data = {
                                                    ForumGroupId: e.data.Id
                                                };
                                                addAntiForgeryToken(data);
                                                return data;
                                            }
                                        }
                                    },
                                    schema: {
                                        data: "Data",
                                        total: "Total",
                                        errors: "Errors"
                                    },
                                    error: function(e) {
                                        display_kendoui_grid_error(e);
                                        // Cancel the changes
                                        this.cancelChanges();
                                    },
                                    pageSize: @(Model.ForumSearch.PageSize),
                                    serverPaging: true,
                                    serverFiltering: true,
                                    serverSorting: true
                                },
                                scrollable: false,
                                pageable: {
                                    refresh: true,
                                    pageSizes: [@(Model.ForumSearch.AvailablePageSizes)],
                                    @await Html.PartialAsync("_GridPagerMessages")
                                },
                                columns: [
                                    {
                                        field: "Name",
                                        title: "@T("Admin.ContentManagement.Forums.Forum.Fields.Name")",
                                        width: 300
                                    }, {
                                        field: "DisplayOrder",
                                        title: "@T("Admin.ContentManagement.Forums.Forum.Fields.DisplayOrder")",
                                        width: 150
                                    }, {
                                        field: "CreatedOn",
                                        title: "@T("Admin.ContentManagement.Forums.Forum.Fields.CreatedOn")",
                                        width: 150,
                                        type: "date",
                                        format: "{0:G}"
                                    }, {
                                        field: "Id",
                                        title: "@T("Admin.Common.Edit")",
                                        width: 80,
                                        headerAttributes: { style: "text-align:center" },
                                        attributes: { style: "text-align:center" },
                                        template: '<a class="btn btn-default" href="EditForum/#=Id#"><i class="fa fa-pencil"></i>@T("Admin.Common.Edit")</a>'
                                    }
                                ]
                            });
                        }
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>